package main

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

/**
 *
 * @param root TreeNode类
 * @return int整型
 */
func sumNumbers(root *TreeNode) int {
	// write code here
	return sum(0, root)
}

func sum(pre int, root *TreeNode) int {
	if root == nil {
		return 0
	}
	res := pre*10 + root.Val
	if root.Left != nil || root.Right != nil {
		return sum(res, root.Left) + sum(res, root.Right)
	}
	return res
}
